#kq = 1 if n is prime, 0 the other way.

#move n into i, j, k for later use 
clear i;
clear x;
clear k;

while n not 0 do;
	incr x;
	incr i;
	incr k;
	incr ka;
	decr n;
end;

incr nlet_two;
incr nlat_two;

clear n_is_two;
incr two;
incr two;

#check k <= 2
while ka not 0 do; #two = two - k
	decr ka;
	decr two;
end;
while two not 0 do; #two = two - k > 0 <=> k < 2
	clear nlet_two;

	clear two;
end;


clear two;
incr two;
incr two;

#check k >= 2
while two not 0 do; #k = k - 2
	decr k;
	decr two;
end;
while k not 0 do; #k - 2 >= 0 <=> k >=2
	clear nlat_two;

	clear k;
end;

while nlet_two not 0 do;
	while nlat_two not 0 do;
		clear n_is_two;
		incr n_is_two;		

		clear nlat_two;
	end;
	clear nlet_two;
end;

incr n_is_not_two;

while n_is_two not 0 do;
	clear i; #don't check
	incr kq; #it is prime
	clear n_is_not_two;

	clear n_is_two; #get out of the while
end;

while n_is_not_two not 0 do;

	#prepare for the check
	incr y;
	incr y;
	decr i;
	decr i;
	clear kq;
	
	clear n_is_not_two;#get out of the while
end;


while i not 0 do;
	clear kq;
	incr kq;

	#now set n = x % y
	clear n;
	copy x to l;
	incr l;
	while l not 0 do;
		copy l to n;
		clear j;

		while y not 0 do;	
			decr l;
			decr y;
			incr j;
		end;
		#restore y
		while j not 0 do;
			incr y;
			decr j;
		end;
	end;
	decr n;

	#if n != 0 then k = 0
	incr k;
	while n not 0 do;
		clear k;
		clear n;
	end;

	#if k != 0 then n = 0 then ...
	while k not 0 do;
		clear kq;
		clear i;
		clear k;
	end;
	decr i;
	incr y;
end;

